package com.example.start.controller;

import com.example.start.common.CommonResp;
import com.example.start.common.PageResp;
import com.example.start.entity.User;
import com.example.start.req.UserReq;
import com.example.start.req.UserSaveReq;
import com.example.start.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/getList")
    public CommonResp getList(UserReq userReq){
        CommonResp<PageResp<User>> resp = new CommonResp<>();
        PageResp<User> list=userService.getList(userReq);
        resp.setContent(list);
        return resp;
    }
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        CommonResp<User> resp = new CommonResp<>();
        userService.delete(id);
        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@RequestBody UserSaveReq userSaveReq){
        CommonResp<User> resp = new CommonResp<>();
        userService.save(userSaveReq);
        return resp;

    }

}
